﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace ChatBox.ViewModels
{
  public class AboutViewModel : ViewModelBase
  {
    #region Constructors

    public AboutViewModel()
      : base()
    {
      this._assembly = Assembly.GetEntryAssembly();
    }

    #endregion

    #region Public Properties

    public string Title
    {
      get
      {
        return this.GetCustomAttribute<AssemblyTitleAttribute>().Title;
      }
    }

    public string Description
    {
      get
      {
        return this.GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
      }
    }

    public string Version
    {
      get
      {
        return this.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
      }
    }

    public string Company
    {
      get
      {
        return this.GetCustomAttribute<AssemblyCompanyAttribute>().Company;
      }
    }

    public string Copyright
    {
      get
      {
        return this.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;
      }
    }

    #endregion

    #region Private Methods

    private T GetCustomAttribute<T>() where T : Attribute
    {
      object[] customAttributes = _assembly.GetCustomAttributes( typeof( T ), false );

      if ( ( customAttributes != null ) && ( customAttributes.Length > 0 ) )
      {
        return ( ( T )customAttributes[0] );
      }

      throw new InvalidOperationException();
    }

    #endregion

    #region Private Variables

    private readonly Assembly _assembly;

    #endregion
  }
}
